<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    class Cat {
        constructor(name, color) {
            this.name = name;
            this.color = color;
        }

        // 静态属性和方法   =>  构造函数自己的方法  
        static hellow = "猫";
        static isCat(arg) {
            if (arg && arg.constructor === Cat) return true;
            return false;
        };

        // 拓展: 私有的属性和方法(新增)(只允许构造函数内自己访问)
        // #posX = null; // this.posX = null
        // #posY = null;

        // 公有的属性和方法 (动态属性和方法)
        // 注意:class中 直接定义的变量存储在实例化对象中
        // posX = null; // this.posX = null
        // posY = null;

        species = "猫";
        call(){
            console.log("喵喵");
        };
        skill(){
            console.log("捉老鼠");
        };
        say(){
            console.log(this.name, this.color);
        };

        getPos() {
            document.onclick = (e) => {
                var e = e || window.event;
                this.posX = e.pageX;
                this.posY = e.pageY;
                console.log(this);
            }
        }

    }

    console.dir(Cat);
    var Tom = new Cat("Tom", "blue")
    console.log(Tom);
    Tom.getPos()

</script>

</html>